package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Permission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @创建人 红莲
 * @创建时间 2020/9/1 15:19
 * @版本 1.0
 * @描述
 */
@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionDao permissionDao;

    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer pageSize = queryPageBean.getPageSize();
        Integer currentPage = queryPageBean.getCurrentPage();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage, pageSize);
        Page<Permission> page = permissionDao.findByCondition(queryString);
        return new PageResult(page.getTotal(), page.getResult());
    }

    public List<Permission> findAllPermission() {
        return permissionDao.findAllPermission();
    }

    public void add(Permission permission) {
        permissionDao.add(permission);
    }

    public Permission findById(Integer id) {
        return permissionDao.findById(id);
    }

    public void update(Permission permission) {
        permissionDao.update(permission);
    }

    public void delete(Integer id) {
        permissionDao.delete(id);
    }
}
